package ru.pachkun.home.russianpost.info;

import org.openqa.selenium.WebDriver;

import ru.pachkun.home.russianpost.info.logicinterface.LoginHelperInterface;
import ru.pachkun.home.russianpost.info.logicinterface.NavigationHelperInterface;
import ru.pachkun.home.util.Browser;
import ru.pachkun.home.util.PropertyLoader;
import ru.pachkun.home.webdriver.WebDriverFactory;

public class ApplicationManager {
	private LoginHelperInterface loginHelper;
	private NavigationHelperInterface navigationHelper;
	private MRPORegistrationHealper mrpoRegistrationHealper;

	private WebDriver driver;
	private String baseUrl;

	public ApplicationManager() {
		baseUrl = PropertyLoader.loadProperty("site.url");
		String gridHubUrl = PropertyLoader.loadProperty("grid2.hub");

		Browser browser = new Browser();
		browser.setName(PropertyLoader.loadProperty("browser.name"));
		browser.setVersion(PropertyLoader.loadProperty("browser.version"));
		browser.setPlatform(PropertyLoader.loadProperty("browser.platform"));

		String username = PropertyLoader.loadProperty("user.username");
		String password = PropertyLoader.loadProperty("user.password");

		driver = WebDriverFactory.getInstance(gridHubUrl, browser, username,
				password);
		
		loginHelper=new LoginHelper(this);
		navigationHelper = new NavigationHelper(this);
		mrpoRegistrationHealper= new MRPORegistrationHealper(this);
		
		
		getNavigationHelper().openMainPage();
	}

	public MRPORegistrationHealper getMrpoRegistrationHealper() {
		return mrpoRegistrationHealper;
	}

	public NavigationHelperInterface getNavigationHelper() {
		return navigationHelper;
	}

	public LoginHelperInterface getLoginHelper() {
		return loginHelper;
	}

	protected WebDriver getWebDriver() {
		return driver;
	}

	protected String getBaseUrl() {
		return baseUrl;
	}

	public void stop() {
		if (driver != null) {
			driver.quit();
		}
	}
}
